package com.sidianzhong.sdz.service.impl;

import com.github.pagehelper.PageHelper;
import com.sidianzhong.sdz.mapper.*;
import com.sidianzhong.sdz.model.*;
import com.sidianzhong.sdz.service.*;
import com.sidianzhong.sdz.utils.PageInfo;
import com.sidianzhong.sdz.utils.Tools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;


/**
* Created by hxgqh on 2016/1/7.
*/
@Service
@Transactional
public class WebInspectionstaffrecordServiceImpl implements WebInspectionstaffrecordService{
    protected static final Logger LOG = LoggerFactory.getLogger(WebInspectionstaffrecordServiceImpl.class);

    // 将所有的modelMapper注入
    @Autowired
    private WebInspectionstaffrecordMapper webInspectionstaffrecordMapper;


    @Override
    public WebInspectionstaffrecord create(WebInspectionstaffrecord item) {

         webInspectionstaffrecordMapper.insert(item);
         return item;
    }

    @Override
    public int delete(Integer id) {
        return webInspectionstaffrecordMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(WebInspectionstaffrecord item) {

        return webInspectionstaffrecordMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public WebInspectionstaffrecord get(Integer id) {
        return webInspectionstaffrecordMapper.selectByPrimaryKey(id);
    }
    @Override
     public PageInfo<WebInspectionstaffrecord> getListWithPaging(Integer pageNum, Integer pageSize,
                                                  String sortItem, String sortOrder,WebInspectionstaffrecord item){

        WebInspectionstaffrecordExample  example = new WebInspectionstaffrecordExample();
        WebInspectionstaffrecordExample.Criteria criteria = example.createCriteria();
        if(item.getRecordid() != null ){
            criteria.andRecordidEqualTo(item.getRecordid());
        }
        if(item.getStaffname() != null ){
            criteria.andStaffnameEqualTo(item.getStaffname());
        }

        example.setOrderByClause(Tools.humpToLine(sortItem)+" "+sortOrder);
        PageHelper.startPage(pageNum, pageSize);
        List< WebInspectionstaffrecord> list = this.webInspectionstaffrecordMapper.selectByExample(example);
        PageInfo result = new PageInfo(list);

        return result;

     }

    @Override
    public int batchInsert(List<WebInspectionstaffrecord> list) {
       return this.webInspectionstaffrecordMapper.batchInsert(list);

    }

    @Override
    public List<WebInspectionstaffrecord> getByrecordid(Integer recordid) {
        WebInspectionstaffrecordExample  example = new WebInspectionstaffrecordExample();
        WebInspectionstaffrecordExample.Criteria criteria = example.createCriteria();
        criteria.andRecordidEqualTo(recordid);
        List< WebInspectionstaffrecord> list = this.webInspectionstaffrecordMapper.selectByExample(example);
        return  list;
    }

}
